//
//  StatusForwordTableViewCell.swift
//  Super_WeiBo
//
//  Created by SuperMac on 16/5/3.
//  Copyright © 2016年 lc. All rights reserved.
//

import UIKit

class StatusForwordTableViewCell: StatusTableViewCell
{
    
    /// 微博模型,重写父类属性的didSet方法，不会覆盖父类操作
    override var status: Status?{
        didSet
        {
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            forwordLabel.attributedText = EmoticonPackage.emoticonString("@" + name + ":  " + text)
        }
    }
    
    override func setupUI() {
        super.setupUI()
       // 添加子空间
        contentView.insertSubview(forwordButton, belowSubview: picView)
        contentView.insertSubview(forwordLabel, aboveSubview: forwordButton)
        
        
        // 布局转发背景
        forwordButton.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -10, y: 10))
        forwordButton.xmg_AlignVertical(type: XMG_AlignType.TopRight, referView: footerV, size: nil)
        
        // 布局转发正文
//        forwordLabel.text = "picWidthCons = picView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Width)"
        forwordLabel.xmg_AlignInner(type: XMG_AlignType.TopLeft, referView: forwordButton, size: nil, offset: CGPoint(x: 10, y: 10))
        
        // 重新调整转发配图位置
        let cons = picView.xmg_AlignVertical(type: XMG_AlignType.BottomLeft, referView: forwordLabel, size: CGSizeZero, offset: CGPoint(x: 0, y: 10))
        // 获得配图 宽、高约束（以便进行更改）
        picWidthCons = picView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Width)
        picHeightCons = picView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Height)
        picTopCons = picView.xmg_Constraint(cons, attribute: NSLayoutAttribute.Top)
    }
    
    // MARK: - 懒加载
    /// 转发微博正文
    private lazy var forwordLabel: UILabel = {
        var l = UILabel.createLabel(UIColor.darkGrayColor(), fontSize: 14)
        l.numberOfLines = 0
        l.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 20
        return l
    }()
    
    private lazy var forwordButton: UIButton = {
       
        let btn = UIButton()
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        return btn
    }()
}
